package lesson02;

import java.sql.ResultSet;
import java.sql.SQLException;

public class testJDBC {
    public static void main(String[] args) {
        try {
            // 查询数据库
            String sql = "SELECT * FROM test_table";
            ResultSet resultSet = JDBCUtils.queryData(sql);
            systemOutData(resultSet);

            //修改
            sql = "UPDATE test_table set test1 = '6' where IS_REPAY_LENDING = '2'";
            JDBCUtils.operateData(sql);

            //查询
            sql = "SELECT * FROM test_table";
            resultSet = JDBCUtils.queryData(sql);
            systemOutData(resultSet);

            //释放连接
            JDBCUtils.release(resultSet);

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    /**
     * 打印查询数据
     * @param resultSet 查询结果
     * @throws SQLException
     */
    private static void systemOutData(ResultSet resultSet) throws SQLException {
        // 处理查询结果
        while (resultSet.next()) {
            String test1 = resultSet.getString("test1");
            String makeLendingTime = resultSet.getString("MAKE_LENDING_TIME");
            String isRepayLending = resultSet.getString("IS_REPAY_LENDING");

            System.out.println("test1: " + test1 + ", makeLendingTime: " + makeLendingTime + ", isRepayLending: " + isRepayLending);
        }
    }
}
